<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>货物价格管理页面</title>
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.css">

    <style>
        body {
            margin:0;
            padding:0;
            font-family:sans-serif;
            background:#2C2255;
            background:url(../image/水漫漫.jpg);
            background-repeat: no-repeat;
            background-size:100%;
            font-size: 20px;
            font-family:STXingkai;
            color: #59ec0a;
        }
        a{
            text-decoration:none;
        }
        button{
            margin:10px;
        }
        th{
            width:300px;

        }
        td{
            width:200px;
            height:80px;
        }
    </style>
</head>
<body>
<h1>货物价格管理页面</h1>
<div id="matterPrice">
    <table id="matterPrice-table" >
        <button data-toggle="modal" data-target="#myModal" class="btn btn-warning modify"  id="insert-customer" >添加新货物</button>
        店名：<input id="itemsName" placeholder="请输入货物名称">
        地址：<input id="itemsUnit"  placeholder="请输入单位">
        <button @click="selMatterPriceBYCondition()" class="btn btn-warning">查询货物</button>
        <button @click="delmatterPrice()" id="delmatterPrice" class="btn btn-danger">删除货物</button>
        <tr>
            <th ><input id="checkAll" type="checkbox" @click="allCheck"></th>
            <th>货物编号</th>
            <th>货物名称</th>
            <th>货物单位</th>
            <th>货物税率</th>
            <th>货物成本单价</th>
            <th>货物加工运输单价</th>
            <th>货物库存量</th>
            <th>操作</th>
        </tr>
        <tr v-for="matterPrice in list" @click="trCheck(event)">
            <td ><input class="check" type="checkbox" :value="matterPrice.itemsNo" @click="isCheckAll"></td>
            <td >{{matterPrice.itemsNo}}</td>
            <td >{{matterPrice.itemsName}}</td>
            <td >{{matterPrice.itemsUnit}}</td>
            <td ><input type="number" style="border:none;background-color:transparent;color: #59ec0a;" v-model="matterPrice.itemsTax"></td>
            <td ><input type="number" style="border:none;background-color:transparent;color: #59ec0a;" v-model="matterPrice.itemsCost"></td>
            <td ><input type="number" style="border:none;background-color:transparent;color: #59ec0a;" v-model="matterPrice.itemsAddTranCost"></td>
            <td ><input type="number" style="border:none;background-color:transparent;color: #59ec0a;" v-model="matterPrice.itemsStoreCounts"></td>
            <td>
                <button v-on:click="updMatterPrice(matterPrice)" class="btn btn-danger ">修改货物信息</button>
            </td>
        </tr>
    </table>
    <!--            分页区域-->
    <div class="pagination-div">
        <ul class="pagination" id="page-ul" >
            <li class="page-item">
                <a class="page-link" href="javascript:void(0);" @click="cutPage(1)">首页</a>
            </li>
            <li class="page-item" v-if="page.pageNow!=1">
                <a class="page-link" href="javascript:void(0);"
                   @click="cutPage(page.pageNow-1)">{{page.pageNow-1}}</a></li>
            <li class="page-item active">
                <a class="page-link" href="javascript:void(0);">{{page.pageNow}}</a>
            </li>
            <li class="page-item" v-if="page.pageNow!=page.pageTotal">
                <a class="page-link" href="javascript:void(0);"
                   @click="cutPage(page.pageNow+1)">{{page.pageNow+1}}</a>
            </li>
            <li class="page-item">
                <a class="page-link" href="javascript:void(0);"
                   @click="cutPage(page.pageTotal)">尾页</a>
            </li>
            <li class="page-item">
                <a class="page-link" href="javascript:void(0);">共有{{page.count}}条数据</a>
            </li>
            <li class="page-item">
                <a class="page-link" href="javascript:void(0);">共有{{page.pageTotal}}页</a>
            </li>
        </ul>
    </div>

    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog"  >
            <div class="modal-content" id="myModal-smile" style=" height: 690px;margin: 0">
                <div class="modal-body" >
                    <h1>添加货物信息</h1>
                    <form id="matterPrice-form">
                        <div class="form-group">
                            <label for="itemsName">货物名称:</label>
                            <input type="text" class="form-control"  name="itemsName"  >
                        </div>

                        <div class="form-group">
                            <label for="itemsUnit">货物单位：</label>
                            <input type="text" class="form-control"  name="itemsUnit" >
                        </div>

                        <div class="form-group">
                            <label for="itemsTax">货物税率：</label>
                            <input type="number" class="form-control" id="itemsTax" name="itemsTax" >
                        </div>


                        <div class="form-group">
                            <label for="itemsCost">货物成本单价：</label>
                            <input type="number" class="form-control" id="itemsCost" name="itemsCost">
                        </div>

                        <div class="form-group">
                            <label for="itemsAddTranCost">货物加工运输单价：</label>
                            <input type="number" class="form-control" id="itemsAddTranCost" name="itemsAddTranCost">
                        </div>

                        <div class="form-group">
                            <label for="itemsStoreCounts">货物库存量：</label>
                            <input type="number" class="form-control" id="itemsStoreCounts" name="itemsStoreCounts">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" id="refresh" class="btn btn-default" @click="close()" data-dismiss="modal">提交并关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>

<!--引入js文件-->
<script type="text/javascript" src="../css/jquery-3.4.1.js"></script>
<script src="../bootstrap/js/bootstrap.js" ></script>
<script src="../vue/vue.js" charset="utf-8"></script>
<script type="text/javascript" src="../css/my.js"></script>

<script>
    let matterPriceTabVue

    // 查询客户 需要接受一个当前页参数
    function selMatterPrice(pageNow,itemsName,itemsUnit) {
        let map = [];
        $.ajax({
            type: "post",
            url: "../MatterPriceController/selMatterPrice",
            dataType: "json",
            data:{pageNow:pageNow, pageCount:5,itemsName:itemsName,itemsUnit:itemsUnit},
            async: false,
            success: function (data) {
                map = data;
            }
        });
        return map;
    }
    /*创建一个map装查询到的第一页的数据*/
    let map = selMatterPrice(1,null,null);
    console.log(map);
    //加载分页数据
    matterPriceTabVue = new Vue({
        el: '#matterPrice',
        data: {
            list: map.list,// 展示表格
            page: map // 用于分页
        },
        methods: {
            //切换页方法 参数为当前按钮所代表的对应页
            cutPage: function (pageNow) {
                let itemsName = $("#itemsName").val();
                let itemsUnit = $("#itemsUnit").val();
                //查询要切换页的数据。把结果从新给表格赋值
                matterPriceTabVue.list = selMatterPrice(pageNow,itemsName,itemsUnit).list;
                //把分页的vue重新赋值。
                matterPriceTabVue.page.pageNow = pageNow;
            },
            //模态框关闭提交修改
            close:function () {
                $.ajax({
                    type:"post",
                    url:"../MatterPriceController/addMatterPrice",
                    data:$("#matterPrice-form").serialize(),
                    dataType:"json",
                    success:function (json) {
                        alert(json.msg);
                        window.location.reload();
                    }
                })
            },
            //条件查询重新调用查询方法
            selMatterPriceBYCondition:function(){
                //获取两个input框的数据
                let itemsName = $("#itemsName").val();
                let itemsUnit = $("#itemsUnit").val();
                matterPriceTabVue.list = selCustomer(1,itemsName,itemsUnit).list;
                matterPriceTabVue.page = selCustomer(1,itemsName,itemsUnit);
                console.log(matterPriceTabVue.page);
            },
            allCheck:function () {
                eventHub.$emit("allCheck",null);
            },
            isCheckAll:function () {
                eventHub.$emit("isCheckAll",null);
            },
            trCheck:function (event) {
                eventHub.$emit("trCheck",event);
            },
            delmatterPrice:function () {
                let mpIds = '';
                //获取被选中的复选框的id值 each()遍历
                $(".check").each(function () {
                    //对所有符合该选择器的元素进行操作
                    //判断该复选框是否选中
                    if(this.checked){
                        mpIds+=this.value + ",";
                        if(mpIds=="") return;
                        $.ajax({
                            type: "post",
                            url: "../MatterPriceController/delMatterPrice",
                            data: {mpIds: mpIds},
                            dataType: "json",
                            success: function (data) {
                                alert(data.msg);
                                window.location.reload();
                            }
                        });
                    }
                });
            },
            updMatterPrice:function (matterPrice) {
                $.ajax({
                    type: "post",
                    url: "../MatterPriceController/updMatterPrice",
                    data: matterPrice,
                    dataType: "json",
                    success: function (data) {
                        alert(data.msg);
                        window.location.reload();
                    }
                });
            }
        }
    });

</script>
</body>
</html>